/**
 * $Id: SmsUtils.java Jun 1, 2015 10:32:46 AM hdp
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aurora.base.util;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aurora.app.constant.Conf;
import com.cloopen.rest.sdk.CCPRestSDK;

/**
 * 发送短信工具
 * <p>创建时间: Jun 1, 2015 10:32:46 AM</p>
 * @author <a href="mailto:hongdanping@163.com">hdp</a>
 * @version V1.0
 * @since V1.0
 */
public final class SmsUtils {
	/**
	 * 日志
	 */
	private static final Logger LOG = LoggerFactory.getLogger(SmsUtils.class);
	
	private static final CCPRestSDK restAPI;
	
	static {
		restAPI = new CCPRestSDK();
		// https://app.cloopen.com:8883 生产环境
		restAPI.init(Conf.SMS_HOST, Conf.SMS_PORT);// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
		restAPI.setAccount(Conf.SMS_SID, Conf.SMS_TOKEN);// 初始化主帐号名称和主帐号令牌
		restAPI.setAppId(Conf.SMS_APPID);// 初始化应用ID
	}
	
	private SmsUtils() {
		throw new RuntimeException("can't init");
	}
	
	public static final boolean send(String phone, String verifycode) {
		try {
			Map<String, Object> result = restAPI.sendTemplateSMS(phone, Conf.SMS_TEMPLATE, new String[] { verifycode });
			return null != result && "000000".equals(result.get("statusCode"));
		} catch (Exception e) {
			LOG.error(e.getMessage(), e);
		}
		return false;
	}
}
